const host = "https://ash.xiegangsir.com/api/v3/";

function request (url, method, data, header = {}) {
    wx.showLoading({
        title: '加载中' // 数据请求前loading
    });
    return new Promise((resolve, reject) => {
        wx.request({
            url: host + url, // 仅为示例，并非真实的接口地址
            method: method,
            data: data,
            header: {
                "Content-Type": "application/json",
                "Accept": "application/json",
                "Authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6ImZjZGUwOWJhOTAwZDA1OTFlMGU3NDdjYzA0M2U3NTUzNjYxOTY2OGI1Zjc3MDJkNDE4YTRjYzExZTUyZmNiNWY2NDhmYjZjOTY4MTRkYWJjIn0.eyJhdWQiOiI5IiwianRpIjoiZmNkZTA5YmE5MDBkMDU5MWUwZTc0N2NjMDQzZTc1NTM2NjE5NjY4YjVmNzcwMmQ0MThhNGNjMTFlNTJmY2I1ZjY0OGZiNmM5NjgxNGRhYmMiLCJpYXQiOjE1NDU2NTcyNzMsIm5iZiI6MTU0NTY1NzI3MywiZXhwIjoxNTc3MTkzMjczLCJzdWIiOiIzMDU2NyIsInNjb3BlcyI6W119.G1-bGvyazpUzZTKCmIRJRnosscMxvmVZQtl8AjYE_szcwNImpVS1pdlA5BOunTHsXMT2LoMWl-TI5hPEptQBb7ginqF-cftHNaGuI3yXhDeuKAC73FDqRhNOAWXOizpCjJK_mcZbC8zVC4Yakcuth2CkQTfRYVXwTDxdMJqDWroG7Ts7P2Z5Z_gCuprhlmapA0F0IW55nQgxeQFNXcnYcFuY0gOWHZpOJrPdkT1PKhlj49IqypPbxz2UVmawYn8ccrPMe2lvTMKUYBUiZZTuByjS8pSgqPiWcauEVSsif71HeQ58Sm4v5l5HeVCenCPcxp8HrwujXbnetyGg_ls2IGu5ygUj6ArVY6M8gZRYRmV9Az6McY3gRo00jfRWMSDiRXTH99nSBvvkOGJr8bmgXiRHzKAUznl5EG_3Lj7EhaGTUqJ8vBwpBQO89l6-4__O5L0nZha4CQUomd9DgU9j2n6iNdZPpk4n5gTZGBcZod3aqL-NjI-m_hJJjDmbWYisj4hdTCLpcjYwLTRHqBU6zu5D-MTZdeYkV-p7fk8FQFvpcUKiHYX95agdw_hJ3exTL_oaiWDGPMp1hw9rL-twhkC6092Z-zloHVFK8bXSx25a8hAzMHMqT0hcGAus5jjvso3J_GAIz5FtePkP5NjXPrIzZfjFDo5b84n7UeL1cco"
            },
            success: function (res) {
                wx.hideLoading()
                resolve(res.data)
            },
            fail: function (res) {
                wx.hideLoading()
                // reject(false)
            },
            complete: function () {
                wx.hideLoading()
            }
        })
    })
}

function get (obj) {
    return request(obj.url, 'GET', obj.data)
}

function post (obj) {
    return request(obj.url, 'POST', obj.data)
}

export default {
    request,
    get,
    post,
    host
}